package it.lovaex.scb.factory;

import java.math.BigDecimal;

public class DiscountRateFactory implements IDiscountRateFactory{

	private static final String GROCERY = "Grocery";
	private static final String BOOK = "Book";
	
	private static final BigDecimal TOTTHRESHOLD = BigDecimal.valueOf(40);
	private static final BigDecimal ADDITIONALDISCOUNT = BigDecimal.valueOf(0.05);

	@Override
	public BigDecimal getByItemCode(String itemCode) {

		if(itemCode.equals(GROCERY))
			return BigDecimal.valueOf(0.075);
		if(itemCode.equals(BOOK))
			return BigDecimal.valueOf(0.12);

		return BigDecimal.ZERO;
	}

	@Override
	public BigDecimal getByTotal(BigDecimal tot) {
		BigDecimal additionalDiscount = new BigDecimal(0);
		if(tot.compareTo(TOTTHRESHOLD) > 0)
			additionalDiscount = ADDITIONALDISCOUNT;
		return additionalDiscount;
	}
}
